<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>活动后台设置</title>
    <style>
        input{
            width: 50px;
        }
    </style>
    <script src="/plugins/JQuery/jquery.min.js"></script>
</head>
<body>
<p>配置活动时间</p>
年：<input type="number" min="2019" id="year"/>
月：<input type="number" min="01" id="month"/>
日：<input type="number" min="01" id="date"/>
时：<input type="number" min="01" id="hours"/>
分：<input type="number" min="01" id="minutes"/>
<p>配置活动时间</p>
活动时常（秒）：<input type="number"min="01" id="activity" value="120"/>
<button onclick="initActivity()">活动生效</button>
<button onclick="linkIndex()">跳转到活动首页</button>
</body>
<script>
    $(function () {
        initInput();
    })
    function initInput(){
        //获取20分钟之后的时间
        var date = getAfterTime(20);

        $('#year').val(date.getFullYear());
        $('#month').val(date.getMonth()+1);
        $('#date').val(date.getDate());
        $('#hours').val(date.getHours());
        $('#minutes').val(date.getMinutes());
    }
    function getAfterTime(after) {
        var date = new Date();
        var min=date.getMinutes();
        date.setMinutes(min+after);
        return date;
    }
    function linkIndex(){
        window.location.href="/manage";
    }
    function initActivity(){
        var year = $('#year').val();
        var month = $('#month').val();
        var date = $('#date').val();
        var hours = $('#hours').val();
        var minutes = $('#minutes').val();
        var activity = $('#activity').val();
        var activityUrl = $('#activityUrl').val();
        if(
            year == null || year == '' ||
            month == null || month == '' ||
            date == null || date == '' ||
            hours == null || hours == '' ||
            activity == null || activity == '' ||
            // activityUrl == null || activityUrl == '' ||
            minutes == null || minutes == ''
        ){
            alert("请正确的填写时间");
            return;
        }
        var url = "/initActivity.do";
        var param = {};
        param.year = year;
        param.month = month;
        param.date = date;
        param.hours = hours;
        param.minutes = minutes;
        param.activityLength = activity;
        // param.url = activityUrl;
        $.post(url,param,function(data){
            if(data.code == 200){
                alert("活动已经成功生效");
            }else{
                alert("系统内部错误，请联系管理员");
            }
        });
    }

</script>
</html>